package com.igeek.collateral.config;

import com.igeek.collateral.job.CleanImgJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * TODO
 *
 * @author chemin
 * @since 2024/7/16
 */
@Configuration
public class QuartzConfig {

    //定义清除图片的工作明细
    @Bean
    public JobDetail cleanImgJobDetail(){
        return JobBuilder.newJob(CleanImgJob.class).storeDurably().build();
    }

    //定义清除图片的触发器
    @Bean
    public Trigger cleanImgTrigger(){
        //构建定时任务，并指定cron表达式  0 0 2 * * ?   每天凌晨两点
        ScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 2 * * ? ");
        return TriggerBuilder.newTrigger().forJob(cleanImgJobDetail()).withSchedule(scheduleBuilder).build();
    }

}
